package com.example.food.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.food.activity.StoreclassiDetailActivity;
import com.example.food.bean.FoodClassBean;
import com.example.home.R;

import java.util.List;

import static com.example.home.tool.StaticActi.ip;

public class FoodclassiAdapter extends RecyclerView.Adapter<FoodclassiAdapter.MyHolder>{
    private Context context;
    private List<FoodClassBean.DataBean> list;


    public FoodclassiAdapter(Context context, List<FoodClassBean.DataBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public FoodclassiAdapter.MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_food,null);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(200,220);
        view.setLayoutParams(layoutParams);
        return new FoodclassiAdapter.MyHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull FoodclassiAdapter.MyHolder holder, int position) {
        Glide.with(context).load(ip+list.get(position).getImgUrl()).into(holder.img);
        holder.text.setText(list.get(position).getThemeName());

        //点击进入对应类别的店家列表页面
        holder.li_.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, StoreclassiDetailActivity.class);
                intent.putExtra("StoreId",String.valueOf(list.get(position).getId()));
                context.startActivity(intent);
            }
        });
    }



    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    class MyHolder extends RecyclerView.ViewHolder {

        private final ImageView img;
        private final TextView text;
        private final RelativeLayout li_;

        public MyHolder(@NonNull View itemView) {
            super(itemView);
            img = itemView.findViewById(R.id.img);
            text = itemView.findViewById(R.id.text);
            li_ = itemView.findViewById(R.id.li_);
        }
    }


}
